package demo;

import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring/spring-config.xml")
public class DemoTest {
	
	private Log logger = LogFactory.getLog(getClass());
	
	@Autowired
	private SomeService service;
	
	/**
	 * 测试数据存入缓存，第二次请求不访问数据库
	 */
	@Ignore
	@Test
	public void testPutEhcache(){
		logger.info("first enquiries");
		logger.info(service.findUser(1L));
		logger.info("second enquiries");
		logger.info(service.findUser(1L));
	}
	
	
	/**
	 *  测试清空缓存，更新数据，清空缓存
	 */
	@Ignore
	@Test
	public void testUpdateEhcache(){
		
		//重复第一个测试
		logger.info("first enquiries");
		logger.info(service.findUser(1L));
		logger.info("second enquiries");
		logger.info(service.findUser(1L));
		
		
		//新建User，id与之前在缓存中的一致
		User user = new User(1L, "小五", "15830283444");
		service.update(user);
			
		
		//更新后进行第三次请求，从数据库中读取
		logger.info("3rd enquiries");
		logger.info(service.findUser(1L));
	}
	

	/**
	 * 测试集合存取和清空缓存
	 */
	@Test
	public void testListEhcache(){
		
		
		//重复第一个测试
		logger.info("first enquiries");
		logger.info(service.findAllUsers());
		logger.info("second enquiries");
		logger.info(service.findAllUsers());
		
		
		//新建User，id与之前在缓存中的一致
		User user = new User(22L, "小五", "15830283444");
		service.addUser(user);
		
			
		
		//更新后进行第三次请求，从数据库中读取
		logger.info("3rd enquiries");
		logger.info(service.findAllUsers());
		
	}
	
	
	


}
